package com.flyduck.mybatis.controller;

import com.flyduck.mybatis.entity.User;
import com.flyduck.mybatis.mapper.UserMapper;
import com.flyduck.mybatis.model.UserModel;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 控制器
 *
 * @author flyduck 2020/11/15 22:04
 * @version V1.0
 * @modify by user: LiuHui 2020/11/15
 * @modify by reason:{原因}
 **/
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ModelMapper modelMapper;

    @GetMapping("{id}")
    public UserModel get(@PathVariable Long id) {
        User user  = userMapper.selectByPrimaryKey(id);

        if (user == null || user.getIsDelete()) {
            return null;
        }

        UserModel userModel = modelMapper.map(user, UserModel.class);

        return userModel;
    }
}
